package com.wnxy.replies;

import org.hibernate.validator.HibernateValidator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan({"com.wnxy.replies","com.wnxy.common"})
@EnableFeignClients(basePackages = "com.wnxy.article.api")
public class RepliesApplication {
    public static void main(String[] args) {
        SpringApplication.run(RepliesApplication.class);
    }

    // 配置参数校验快速失败；只要有一个参数校验失败立刻返回。提高效率！
    @Bean
    public Validator fastFail() {
        ValidatorFactory factory = Validation.byProvider(HibernateValidator.class)
                .configure()
                .failFast(true)
                .buildValidatorFactory();
        Validator validator = factory.getValidator();
        return validator;
    }
}